% 10-fold Sampling training and testing
[AllDataSampler] = Ddavid_cross_validation_training_testing(AllData, 10);
FoldNumber = 1;
[AllDataTraining, AllDataTesting, TrueLabelTraining, TrueLabelTesting] = Ddavid_pick_up_fold(AllData, TrueLabel, AllDataSampler, FoldNumber);

% Sampling training and testing
SizeDataTraining = 3000;
[AllDataTraining, AllDataTesting, TrueLabelTraining, TrueLabelTesting, AllDataSampler] = Ddavid_sample_training_testing(AllData, TrueLabel, SizeDataTraining);

% Sampling incomplete labels
SampledDataSize = 600;
SampledLabelSize = 3;

[SampledTrueLabelTraining, SampledDataTraining, SampledOnlyTrueLabelTraining, DataSampler] = Ddavid_sample_label(AllDataTraining, TrueLabelTraining, SampledDataSize, SampledLabelSize);
AllData = [AllDataTraining; AllDataTesting];
TrueLabel = [TrueLabelTraining; TrueLabelTesting];

% SampledTrueLabelTesting = ones(size(TrueLabelTesting, 1), size(TrueLabelTesting, 2)) * (-1);
% SampledTrueLabel = [SampledTrueLabelTraining; SampledTrueLabelTesting];



% Recoverd training data MLkNN
% Method 1: Ddavid_recover_single_label_SVDDandKNN
RecoverK = 5;
K = 10;
R = 0.0;
T = 1;
Method = 1;
RemoveNoLabel = true;

KNNList = Ddavid_find_knn(RecoverK, AllDataTraining);

[ResultRecoverd.HammingLossTraining, ResultRecoverd.HammingLossBeforeTraining, RecoveredTrueLabelTraining] = Ddavid_recover_multi_label(AllDataTraining, TrueLabelTraining, SampledTrueLabelTraining, RecoverK, KNNList, R, T, Method);

AddedPoint.NumberTraining = sum(sum(RecoveredTrueLabelTraining ~= SampledTrueLabelTraining));
AddedPoint.CorrectNumberTraining = sum(sum((RecoveredTrueLabelTraining == 1) & (SampledTrueLabelTraining == -1) & (TrueLabelTraining == 1)));
AddedPoint.CorrectRateTraining = AddedPoint.CorrectNumberTraining / AddedPoint.NumberTraining;

if(RemoveNoLabel == true)
    [RecoveredDataTraining, RecoveredTrueLabelTraining] = Ddavid_remove_no_label_training(AllDataTraining, RecoveredTrueLabelTraining);
else
    RecoveredDataTraining = AllDataTraining;
end

[ResultRecoverd.Prior, ResultRecoverd.PriorN, ResultRecoverd.Cond, ResultRecoverd.CondN] = MLKNN_train(RecoveredDataTraining, RecoveredTrueLabelTraining', K, 1);
[ResultRecoverd.HammingLoss, ResultRecoverd.RankingLoss, ResultRecoverd.OneError, ResultRecoverd.Coverage, ResultRecoverd.Average_Precision, ResultRecoverd.Outputs, ResultRecoverd.Pre_Labels] = MLKNN_test(RecoveredDataTraining, RecoveredTrueLabelTraining', AllDataTesting, TrueLabelTesting', K, ResultRecoverd.Prior, ResultRecoverd.PriorN, ResultRecoverd.Cond, ResultRecoverd.CondN);
